﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CMP.ERP.Model;
using CMP.ERP.BLL;
using System.Data;

namespace CMP.ERP.Admin.Controllers
{
    public class FahuoController : Controller
    {
        //
        // GET: /Fahuo/
        FahuoBLL bll = new FahuoBLL();
        public ActionResult Index(int id)
        {
            return View(bll.GetShipmentsById(id));
        }
        public ActionResult Add( Fahuolist f)
        {
            if(bll.UpdStateAndAddFahuolist(f)>0)
            {
                return Content("<script>alert('发货成功！'); location.href='/Fahuo/FahuoList'</script>");
            }
            else
            {
                return Content("<script>alert('发货失败了！'); location.href='/Fahuo/FahuoList'</script>");
            }
        }
        public ActionResult FahuoList()
        {
            List<Shipments> list = new List<Shipments>();
            DataTable data = bll.GetShipments();
            foreach (DataRow item in data.Rows)
            {
                Shipments s = new Shipments();
                s.Shipments_Id = Convert.ToInt32(item["Shipments_Id"]);
                s.Shipments_data = item["Shipments_data"].ToString();
                s.Shipments_Per = item["Shipments_Per"].ToString();
                s.Shipments_Phone = item["Shipments_Phone"].ToString();
                s.Shipments_State = item["Shipments_State"].ToString();
                s.Express_Company_Name = item["Express_Company_Name"].ToString();
                s.WareHose_Name = item["WareHose_Name"].ToString();
                s.Shipments_SumMoney = Convert.ToInt32(item["Shipments_SumMoney"]);
                list.Add(s);
            }

            return View(list);
        }
        public ActionResult shouhuodo(int id)
        {
            if (bll.shouhuo(id) > 0)
            {
                return Content("<script>alert('收货成功！'); location.href='/Fahuo/FahuoList'</script>");
            }
            else
            {
                return Content("<script>alert('收货失败了！'); location.href='/Fahuo/FahuoList'</script>");
            }
        }
        /// <summary>
        /// 查看订单详情信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult DetailsShipmentsShow(int id)
        {
            ShipmentsBLL sbll = new ShipmentsBLL();
            Session["id"] = Convert.ToInt32(id);
            List<DetailsShipments> list = new List<DetailsShipments>();
            DataTable data = sbll.DetailsShow(id);
            foreach (DataRow item in data.Rows)
            {
                DetailsShipments c = new DetailsShipments();
                c.ShipmentMate_Id = Convert.ToInt32(item["ShipmentMate_Id"]);
                c.Shipments_Id = Convert.ToInt32(item["Shipments_Id"]);
                c.Commodity_Name = item["Commodity_Name"].ToString();
                c.Commodity_number = Convert.ToInt32(item["Commodity_number"]);
                c.Commodity_Weight = Convert.ToInt32(item["Commodity_Weight"]);
                c.Commodity_Remark = item["Commodity_Remark"].ToString();
                c.Commodity_Price = Convert.ToInt32(item["Commodity_Price"]);
                c.CommodityType_Name = item["CommodityType_Name"].ToString();
                c.ShipmentMate_Num = Convert.ToInt32(item["ShipmentMate_Num"]);
                list.Add(c);
            }
            return View(list);
        }
    }
}
